home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / NasheKino (RU).ifs < prev    next >
Text File  |  2005-03-13  |  6KB  |  234 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Yan Sorkin (<link>ysorkin@mail.ru</link>)
  8. Title=NasheKino
  9. Description=Imports russian movies info from NasheKino
  10. Site=http://www.nashekino.ru/
  11. Language=RU
  12. Version=
  13. Requires=3.5.0
  14. Comments= Known issues: - Movie length not supported
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program NasheKino;
  23. const
  24.   BaseAddress = 'http://www.nashekino.ru/';
  25. //  BaseAddress = 'http://localhost/';
  26. var
  27.   MovieName: string;
  28.  
  29. function GetTextBlockFrom(Text: string; StartAt: string): string;
  30. var
  31.   TextBlock: string;
  32.   StartPos, EndPos: Integer;
  33. begin
  34.   TextBlock := Text;
  35.   StartPos := pos(StartAt, TextBlock);
  36.   if StartPos > 0 then
  37.   begin
  38.     Delete(TextBlock, 1, StartPos - 1);
  39.     result := TextBlock;
  40.   end;
  41. end;
  42.  
  43. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  44. var
  45.   i: Integer;
  46. begin
  47.   result := -1;
  48.   if StartAt < 0 then
  49.     StartAt := 0;
  50.   for i := StartAt to List.Count-1 do
  51.     if Pos(Pattern, List.GetString(i)) <> 0 then
  52.     begin
  53.       result := i;
  54.       Break;
  55.     end;
  56. end;
  57.  
  58. procedure AnalyzePage(Address: string);
  59. var
  60.   Page: TStringList;
  61.   LineNr: Integer;
  62.   Line: string;
  63.   TextBlock: string;
  64. begin
  65.   Page := TStringList.Create;
  66.   Page.Text := GetPage(Address);
  67.   if pos('═α°σ ΩΦφε /∩εΦ±Ω/', Page.Text) = 0 then
  68.   begin
  69.     SetField(fieldURL, Address);
  70.     AnalyzeMoviePage(Page);
  71.   end else
  72.   if pos('╧ε τα∩≡ε±≤ "', Page.Text) = 0 then
  73.   begin
  74.     ShowMessage('No movies found');
  75.   end else
  76.   begin
  77.     PickTreeClear;
  78.     LineNr := FindLine('<hr width="100%" size=1 color="black">', Page, 0);
  79.     if LineNr > -1 then
  80.     begin
  81.       PickTreeAdd('Movies', '');
  82.       AddMoviesTitles(Page, LineNr);
  83.     end;
  84.     if PickTreeExec(Address) then
  85.       AnalyzePage(Address);
  86.   end;
  87.   Page.Free;
  88. end;
  89.  
  90. procedure AnalyzeMoviePage(Page: TStringList);
  91. var
  92.   Value, PageText, Text: string;
  93.   LineNr, MovieLength: Integer;
  94.   BeginPos, EndPos: Integer;
  95. begin
  96.  
  97.   // All the info is in one line
  98.   PageText := GetTextBlockFrom( Page.Text, '<a name=0 class=ab12b>' );
  99.   EndPos := pos('├Σσ Γετ∞εµφε ∩≡Φεß≡σ≥σφΦσ Σαφφεπε ⌠Φδⁿ∞α', PageText);
  100.   if EndPos > 0 then
  101.   begin
  102.     PageText := copy( PageText, 1, EndPos - 1 );
  103.   end;
  104.  
  105.   if Length(PageText) > 0 then
  106.   begin
  107.     // Original Title
  108.     BeginPos := 1;
  109.     EndPos := pos('</a>', PageText);
  110.     Value := copy(PageText, BeginPos, EndPos - BeginPos);
  111.     HTMLDecode(Value);
  112.     HTMLRemoveTags(Value);
  113.     SetField(fieldOriginalTitle, Value);
  114.     Delete(PageText, 1, EndPos - 1);
  115.     
  116.     // Alternative titles (skip)
  117.     BeginPos := pos('Σ≡≤πΦσ φατΓαφΦ :', PageText);
  118.     if BeginPos > 0 then Delete(PageText, 1, BeginPos - 1);
  119.  
  120.     // Year
  121.     BeginPos := pos('ab10>, ', PageText) + 7;
  122.     EndPos := pos('πεΣ.', PageText) - 1;
  123.     if EndPos > BeginPos then
  124.     begin
  125.         Value := copy(PageText, BeginPos, EndPos - BeginPos);
  126.         SetField(fieldYear, Value);
  127.         Delete(PageText, 1, EndPos - 1);
  128.     end;
  129.     
  130.     // Length
  131.     BeginPos := pos('πεΣ., ', PageText) + 6;
  132.     EndPos := pos('∞Φφ.', PageText) - 1;
  133.     if EndPos > BeginPos then
  134.     begin
  135.         Value := copy(PageText, BeginPos, EndPos - BeginPos);
  136.         SetField(fieldLength, Value);
  137.         Delete(PageText, 1, EndPos - 1);
  138.     end;
  139.   end;
  140.  
  141.   // Director
  142.   Text := GetTextBlockFrom( PageText, '╨σµΦ±±σ≡(√): ' );
  143.   if Length(Text) > 0 then
  144.   begin
  145.     BeginPos := 14;
  146.     EndPos := pos('<br>', Text);
  147.     if EndPos > BeginPos then
  148.     begin
  149.       Value := copy(Text, BeginPos, EndPos - BeginPos);
  150.       HTMLDecode(Value);
  151.       HTMLRemoveTags(Value);
  152.       SetField(fieldDirector, Value);
  153.     end;
  154.   end;
  155.  
  156.   // Actors
  157.   Text := GetTextBlockFrom( PageText, '└Ω≥σ≡(√): ' );
  158.   if Length(Text) > 0 then
  159.   begin
  160.     BeginPos := 11;
  161.     EndPos := pos('<br>', Text);
  162.     if EndPos > BeginPos then
  163.     begin
  164.       Value := copy(Text, BeginPos, EndPos - BeginPos);
  165.       HTMLDecode(Value);
  166.       HTMLRemoveTags(Value);
  167.       SetField(fieldActors, Value);
  168.     end;
  169.   end;
  170.  
  171.   // Description
  172.   Text := GetTextBlockFrom( PageText, '╬ ⌠Φδⁿ∞σ:' );
  173.   if Length(Text) > 0 then
  174.   begin
  175.     BeginPos := pos('<a class=ab10> ', Text) + 15;
  176.     EndPos := pos('<hr', Text);
  177.     if EndPos > BeginPos then
  178.     begin
  179.       Value := copy(Text, BeginPos, EndPos - BeginPos);
  180.       HTMLDecode(Value);
  181.       Value := StringReplace(Value, '<br>', #13#10);
  182.       Value := StringReplace(Value, '<p', #13#10#13#10 + '<p');
  183.       HTMLRemoveTags(Value);
  184.       SetField(fieldDescription, Value);
  185.     end;
  186.   end;
  187.  
  188.   //DisplayResults;
  189. end;
  190.  
  191. procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
  192. var
  193.   Line: string;
  194.   MovieTitle, MovieAddress, AddrPrefix: string;
  195.   StartPos, EndPos: Integer;
  196. begin
  197.   repeat
  198.     LineNr := LineNr + 1;
  199.     Line := Page.GetString(LineNr);
  200.     StartPos := pos('showfilm.cgi', Line);
  201.     AddrPrefix := 'cgi-bin/';
  202.     if StartPos = 0 then
  203.     begin
  204.       StartPos := pos('data/films', Line);
  205.       AddrPrefix := '';
  206.     end;
  207.     EndPos := pos('</div>', Line);
  208.     if (StartPos > 0) and (EndPos = 0) then
  209.     begin
  210.       MovieAddress := copy(Line, StartPos, pos('">', Line) - StartPos);
  211.       MovieTitle := Line;
  212.       HTMLDecode(Movietitle);
  213.       HTMLRemoveTags(MovieTitle);
  214.       PickTreeAdd(MovieTitle, BaseAddress + AddrPrefix + MovieAddress);
  215.     end;
  216.   until EndPos > 0;
  217. end;
  218.  
  219. begin
  220.   if CheckVersion(3,5,0) then
  221.   begin
  222.     MovieName := GetField(fieldOriginalTitle);
  223.     if MovieName = '' then
  224.       MovieName := GetField(fieldTranslatedTitle);
  225.     if Input('Import from NasheKino', 'Enter the title of the movie:', MovieName) then
  226.     begin
  227.       AnalyzePage('http://www.nashekino.ru/cgi-bin/find.cgi?t=0&sval='+UrlEncode(MovieName));
  228. //      AnalyzePage('http://localhost/search1.htm');
  229.     end;
  230.   end else
  231.   ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  232. end.
  233.  
  234.